﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
/// <summary>
/// 玩家管理器
/// </summary>
public class PlayerManager : SingletonProvider<PlayerManager>
{
    private string mPlayerPath = "Player";
    public Player mPlayer { private set; get; }
    /// <summary>
    /// 创建玩家
    /// </summary>
    /// <param name="mBirthPlace"></param>
    /// <param name="callback"></param>
    public void CreatePlayer(Vector3 mBirthPlace, UnityAction callback)
    {
        PoolManager.GetInstance().GetObject(mPlayerPath, (playerPrefabs) =>
        {
            playerPrefabs.transform.position = mBirthPlace;
            mPlayer = playerPrefabs.GetComponent<Player>();
            playerPrefabs.transform.parent = GameManager.GetInstance().movableObjects;
            if (callback != null)
                callback.Invoke();
        });
    }
    /// <summary>
    /// 删除玩家
    /// </summary>
    public void ClearPlayer()
    {
        mPlayer.ResetData();
        PoolManager.GetInstance().PushObject(mPlayerPath, mPlayer.gameObject);
        mPlayer = null;
    }
}
